package
{
	import flash.display.Bitmap;
	import flash.utils.Dictionary;
	
	import starling.textures.Texture;
	import starling.textures.TextureAtlas;
	import flash.utils.ByteArray;

	public class Assets
	{
		[Embed(source="../assets/exported/default_placeholder.png")]
		public static const TestImage:Class;
		
		private static var gameTextures:Dictionary = new Dictionary();
		public static function getTexture(name:String):Texture {
			if (gameTextures[name] == undefined) {
				var  bitmap:Bitmap
				try
				{
					bitmap = new Assets[name]();
				} 
				catch(error:Error) 
				{
					bitmap = new Assets["TestImage"]();
					trace("asset/class not found " + name+ " using default test image instead");
				}

				gameTextures[name] = Texture.fromBitmap(bitmap);
			}
			
			return gameTextures[name];
		}
		
		[Embed(source="../assets/exported/mySpriteSheet.png")]
		private static const FlyerAtlas:Class;
		
		[Embed(source="../assets/exported/mySpriteSheet.xml",mimeType="application/octet-stream")]
		private static const FlyerAtlasXml:Class;
		
		[Embed(source="../assets/exported/sprites.png")]
		private static const GunnerAtlas:Class;
		
		[Embed(source="../assets/exported/sprites.xml",mimeType="application/octet-stream")]
		private static const GunnerAtlasXml:Class;
		

		
		private static var gameTextureAtlases:Dictionary = new Dictionary();
		public static function getAtlas(name:String):TextureAtlas {
			if(null == gameTextureAtlases[name]) { // old habits die hard
				var texture:Texture = getTexture(name);
				var name2:String = name + "Xml";
				var xml:XML = XML(new Assets[name2]());
				gameTextureAtlases[name] = new TextureAtlas(texture,xml);
			}
			return gameTextureAtlases[name];
		}
		
		[Embed(source="../assets/exported/words.txt",mimeType="application/octet-stream")]
		private static const WordsDictionary:Class
		private static var words:Dictionary = new Dictionary();
		public static function getEmeddedWordList():Dictionary {

			var b:ByteArray = new WordsDictionary();
			var s:String = b.readUTFBytes(b.length);
			var a:Array = s.split("\n");
			//trace(a);

			return words;
		}

//		[Embed(source="../assets/exported/mySpriteSheet.png")]
//		private static const AtlasTextureGame:Class;
//		
//		
//		[Embed(source="../assets/exported/mySpriteSheet.xml",mimeType="application/octet-stream")]
//		private static const AtlasXmlGame:Class;
//	
//			private static var gameTextureAtlas:TextureAtlas;
//			public static function getAtlas():TextureAtlas {
//
//				if(null == gameTextureAtlas) { // old habits die hard
//					var texture:Texture = getTexture("AtlasTextureGame");
//					var xml:XML = XML(new AtlasXmlGame());
//					gameTextureAtlas = new TextureAtlas(texture,xml);
//				}
//				return gameTextureAtlas;
//			}
		
	}
}